<template>
  <div>
    <div style="height: 700px; margin: 25px">
      <!-- 考核模板 -->
      <el-row class="createMUban" v-if="!looks">
        <el-button
          @click="addEquipment()"
          type="success"
          size="small"
        >+ 新增</el-button>
        <el-button
          @click="deleteSelected()"
          type="danger"
          size="small"
          :disabled="deletes"
        >批量删除</el-button>
      </el-row>
      <!-- 表格信息 -->
      <el-row>
        <el-table
          :data="tableData"
          style="width: 100%; color: #333333;font-size: 14px"
          height="700"
          align="center"
          :header-cell-style="{ background: '#ECF1F9' }"
          @selection-change="handleSelectionChangeDepartment"
        >
          <el-table-column type="selection" width="80" align="center"></el-table-column>
          <el-table-column fixed type="index" align="center" label="序号" width="80"></el-table-column>
          <el-table-column prop="content" align="center" label="通知内容" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column align="center" width="40">
            <template slot-scope="scope">
              <a @click="openPeopleList(scope.row)">
                <i>
                  <img src="@/assets/kaohePng/yanJing.png" />
                </i>
              </a>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" align="center" label="发布时间"></el-table-column>
          <el-table-column prop="createBy" align="center" label="发布人" width="120"></el-table-column>

          <el-table-column prop="isRecall" align="center" label="展示状态" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.isRecall==0" style="color:#EF7045 ">展示中</span>
              <span v-if="scope.row.isRecall==2">已撤回</span>
            </template>
          </el-table-column>
          <el-table-column fixed="right" align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.isRecall==0? true:false"
                type="text"
                size="small"
                style="color: #3B95FF"
                @click.native.prevent="returnRow(scope.row)"
              >撤回</el-button>
              <el-button
                @click.native.prevent="deleteRow(scope.row)"
                type="text"
                size="small"
                style="color:#E86565"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <el-pagination
            style="text-align: right;margin-top:16px"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[5, 10]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </el-row>
      </el-row>
    </div>
    <el-dialog
      title="发布绩效通知"
      :visible.sync="centerDialogVisible"
      width="30%"
      style="border-radius:10px"
      center
      @close="delJ('ruleForm')"
    >
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="demo-ruleForm">
        <el-form-item label="通知内容:" prop="content">
          <el-input
            type="textarea"
            :rows="10"
            :show-word-limit="true"
            v-model="ruleForm.content"
            placeholder="请输入"
            style="width:80%;"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addJ('ruleForm')">确认</el-button>
        <el-button @click="delJ('ruleForm')">取消</el-button>
      </span>
    </el-dialog>

    <!-- 查看内容 -->
    <el-dialog
      title="公告内容"
      :visible.sync="centerDialogVisible1"
      width="30%"
      style="border-radius:10px"
      center
    >
      <div style="width:100%;height:auto;border: 1px solid #E4E4E4;padding:2%;border-radius:5px">
        <template>
          <span>{{nameList}}</span>
        </template>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="centerDialogVisible1 = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

  <script>
import {
  deleteGongGao,
  getGongGaoList,
  deleteAllGongGao,
  addJixiao,
  editJixiao
} from "@/api2/kaohe"; //
export default {
  data() {
    return {
      ruleForm: {
        content: ""
      },
      rules: {
        content: [
          { required: true, message: "请输入通知内容", trigger: "blur" }
        ]
      },
      nameList: "",
      centerDialogVisible1: false,
      deletes: true,
      multipleSelectionDepartment: [], // 用于保存选中的行
      gettime: "", //当前时间
      dataTypes: {},
      nameList: [],
      assessUserTypes: "",
      centerDialogVisible: false,
      looks: false,
      tableDatadialog: [], //表格数据
      createThree: false, //建立考核模板按钮的开关
      formLabelWidth: "78px", //label-width
      // 分页属性定义如下{
      pageNum: 1, //当前页
      total: 0, //总条数
      // tableData: [], //当前页码的表格数据
      pageSize: 10, //当前页容量
      // }
      //表格数据数组
      tableData: [],
      userList: []
    };
  },
  created() {
    this.getList(); //获取表格数据
  },
  methods: {
    openPeopleList(e) {
      console.log(e);
      this.nameList = e.content;
      this.centerDialogVisible1 = true;
    },
    //发布绩效
    addJ(formName) {
      const data = {
        content: this.ruleForm.content,
        type: 5
      };
      this.$refs[formName].validate(async valid => {
        if (valid) {
          const res = await addJixiao(data);
          if (res.code == 0) {
            this.$message({
              message: "发布成功",
              type: "success"
            });
            (this.ruleForm = {
              content: ""
            }),
              (this.centerDialogVisible = false);
            this.$refs[formName].resetFields();
            this.getList();
          }
        } else {
          this.$message.error("信息填写不完整!");
          return false;
        }
      });
    },
    //quxiao
    delJ(formName) {
      this.$refs[formName].resetFields();
      (this.ruleForm = {
        content: ""
      }),
        (this.centerDialogVisible = false);
      this.$message({
        message: "已取消"
      });
    },
    // 用于保存选中的行
    handleSelectionChangeDepartment(val) {
      this.multipleSelectionDepartment = val;
      if (val) {
        this.deletes = false;
      } else {
        this.deletes = true;
      }
    },
    // 批量删除
    deleteSelected() {
      this.$confirm("此操作将删除选中所有内容, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let arr = [];
          let vals = this.multipleSelectionDepartment; //选中的值
          if (vals) {
            vals.map(item => {
              arr.push(item.id);
            });
          }
          const ids = { ids: arr.join() };
          deleteAllGongGao(ids).then(res => {
            if (res.code == 0) {
              this.$message.success("删除成功");
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 建立考核模板按钮
    addEquipment() {
      this.centerDialogVisible = true;
    },

    // 表格内撤回按钮的点击事件
    async returnRow(rows) {
      console.log(rows);
      const data = {
        id: rows.id,
        isRecall: 2,
        type: 5
      };
      const res = await editJixiao(data);
      if (res.code == 0) {
        this.$message.success("已撤回");
        this.getList();
      }
    },
    // 表格内删除按钮的点击事件
    deleteRow(rows) {
      const id = rows.id;
      this.$confirm("此操作将删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(res1 => {
          console.log(id);
          deleteGongGao(id).then(res => {
            if (res.data === true) {
              this.$message.success("删除成功");
              const totalPage = Math.ceil((this.total - 1) / this.pageSize);
              // 记住删除最后一条数据时当前码是最后一页
              const pageNums =
                this.pageNum > totalPage ? totalPage : this.pageNum;
              // 重新记录当前页码
              this.pageNum = pageNums < 1 ? 1 : pageNums;
              //删除成功 回调列表接口
              this.getList();
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },

    //分页逻辑{
    //切换每页条数容量
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList(this.pageNum, this.pageSize);
    },
    //切换当前页
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getList();
    },
    //获取表格数据
    getList() {
      const params = {
        queryType: 2,
        type: 5,
        pageNum: this.pageNum,
        pageSize: this.pageSize
      };
      getGongGaoList(params)
        .then(res => {
          this.tableData = res.data;
          this.total = res.total; //总条数
        })
        .catch(e => {
          console.log(e);
        });
    }
    //分页逻辑}
  }
};
</script>

  <style lang="scss" scoped>
.app-container {
  height: 100%;
  background-color: #f4f5fc;
}
.createMUban {
  display: inline-flex;
  align-items: center;
}
/* 共同样式 */
.add_dimension {
  color: blue;
}
.delete_dimension {
  color: red;
}
.add_dimension:hover {
  color: rgb(72, 72, 234);
}
.delete_dimension:hover {
  color: rgb(245, 71, 71);
}
.nextOne {
  margin-top: 25px;
  margin-left: 45%;
  background-color: #0096fe;
}
::v-deep .el-dialog__footer {
  /*width: 0;宽度为0隐藏*/
  text-align: center;
}
// 滚动条样式
::v-deep .el-table__body-wrapper {
  &::-webkit-scrollbar {
    // 整个滚动条
    width: 0; // 纵向滚动条的宽度
    background: rgba(213, 215, 220, 0.3);
    border: none;
  }
  &::-webkit-scrollbar-track {
    // 滚动条轨道
    border: none;
  }
}

::v-deep .el-dialog__header {
  background-color: #ecf1f9;
  border-radius: 10px;
}
::v-deep .el-dialog {
  border-radius: 10px;
}
::v-deep .el-tooltip__popper {
  max-width: 10%;
}

::v-deep .el-tooltip__popper,
.el-tooltip__popper.is-dark {
  background: rgb(48, 65, 86) !important;
  color: #fff !important;
  line-height: 24px;
}
::v-deep .el-table--scrollable-y .el-table__body-wrapper {
  overflow-y: auto;
}

::v-deep .el-table th.gutter {
  display: none;
  width: 0;
}
::v-deep .el-table colgroup col[name="gutter"] {
  display: none;
  width: 0;
}

::v-deep .el-table__body {
  width: 100% !important;
}

::v-deep [data-v-125ad6e6] .el-step.is-horizontal .el-step__line {
  opacity: 0;
}
</style>
